<template>
    <div>
        <van-row>
            <h4>手机测试</h4>
        </van-row>
        <van-row>
            <van-field v-model="baseUrl" label="IP地址" placeholder="请输入地址"/>
        </van-row>
        <van-row>
            <van-button plain hairline type="primary"
            @click="handleChange('on')">打开手电筒</van-button>
            <van-button plain hairline type="primary" style="margin-left: 10px"
                        @click="handleChange('off')">关闭手电筒</van-button>
        </van-row>
        <van-row style="margin-top: 10px">
            <van-button plain hairline type="primary"
                        @click="handleChange('sosOn')">打开闪光灯</van-button>
            <van-button plain hairline type="primary" style="margin-left: 10px"
                        @click="handleChange('sosOff')">关闭闪光灯</van-button>
        </van-row>
        <van-row style="margin-top: 10px">
            <van-field v-model="value" label="说话内容" placeholder="请输入内容"/>
            <van-button plain hairline type="primary" style="margin-left: 10px"
                        @click="handleSpeak">发送</van-button>
        </van-row>
        <van-row style="margin-top: 10px">
            <van-field v-model="musicName" label="歌名" placeholder="请输入歌名"/>
            <van-button plain hairline type="primary" style="margin-left: 10px"
                        @click="handlePlayMusic">播放</van-button>
            <van-button plain hairline type="primary" style="margin-left: 10px"
                        @click="handleStopMusic">停止播放</van-button>
        </van-row>
    </div>
</template>

<script>
    export default {
        name: "phone",
        data() {
            return {
                value:"",
                musicName:"",
                baseUrl: "http://192.168.0.161:8080",
            }
        },
        methods: {
            handleChange(value) {
                console.log(this.value);
                this.$axios.get(this.baseUrl + "?light=" + value).then(
                    response => {
                        console.log("请求成功了1", response.data);
                    },
                    error => {
                        console.log("请求失败了1", error.message)
                    }
                )
            },
            handleSpeak(){
                this.$axios.get(this.baseUrl + "?speak=" + this.value).then(
                    response => {
                        console.log("请求成功了2", response.data);
                    },
                    error => {
                        console.log("请求失败了2", error.message)
                    }
                )
            },
            handlePlayMusic(){
                this.$axios.get(this.baseUrl + "?playMusic=" + this.musicName).then(
                    response => {
                        console.log("请求成功了3", response.data);
                    },
                    error => {
                        console.log("请求失败了3", error.message)
                    }
                )
            },
            handleStopMusic(){
                this.$axios.get(this.baseUrl + "?playMusic=stop").then(
                    response => {
                        console.log("请求成功了3", response.data);
                    },
                    error => {
                        console.log("请求失败了3", error.message)
                    }
                )
            }
        }
    }
</script>

<style scoped>

</style>